package com.mx.recycle_demo.activity

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.mx.recycle_demo.R
import com.mx.recycle_demo.adapt.SimpleImgAdapt
import com.mx.recycleview.manager.CoverFlowLayoutManger
import com.mx.recycleview.utils.Log
import kotlinx.android.synthetic.main.activity_cover_flow.*
import kotlin.random.Random


class CoverFlowActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_cover_flow)
        val adapter = SimpleImgAdapt(
            arrayListOf(
                R.mipmap.item1, R.mipmap.item2, R.mipmap.item3, R.mipmap.item4,
                R.mipmap.item5, R.mipmap.item6
            )
        )
        zRecycleView.setOnItemSelectedListener(object : CoverFlowLayoutManger.OnSelected {
            override fun onItemSelected(position: Int) {
                Log("onItemSelected  $position")
            }
        })
        zRecycleView.setLoop(true)
        zRecycleView.setDebug(true)
        val layoutManager = zRecycleView.coverFlowLayout!!
        zRecycleView.adapter = adapter
        adapter.notifyDataSetChanged()
        adapter.setItemClick { index, record ->
            Toast.makeText(this, "$index", Toast.LENGTH_SHORT).show()
            if (Random.nextBoolean()) {
                zRecycleView.smoothScrollToNext(2)
            } else {
                zRecycleView.smoothScrollToPre(2)
            }
        }
    }
}